# -*- coding: UTF-8 -*-
import json
import types

from django.core import serializers
from django.http import HttpResponse


# json数据

def simplejson(dictdata):
    json_data = serializers.serialize("json", dictdata)
    return HttpResponse(json_data, content_type="application/json")

def singlejson(jsondata):
    return HttpResponse(jsondata, content_type="application/json")

# 遍历查询集 调用model属性转换成dict
def queryset_to_json(queryset):
    obj_arr = []
    for o in queryset:
        obj_arr.append(o.toDict())
    return obj_arr


def allmoble(**kwargs):
    _data_page_json = {}
    for key in kwargs:
        print kwargs[key]
        print type(kwargs[key])
        if isinstance(kwargs[key],str):
            print '这是string'
            _data_page_json[key] = kwargs[key]
        else:
            print '这不是string'
            currentbean = queryset_to_json(kwargs[key])
            _data_page_json[key] = currentbean
    jsondata = json.dumps(_data_page_json)
    return HttpResponse(jsondata, content_type="application/json")


def simplechain():
    pass
